{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn as sns; sns.set_theme()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "# Add colormap display methods to matplotlib colormaps.\n",
    "# These are forthcoming in matplotlib 3.4, but, the matplotlib display\n",
    "# method includes the colormap name, which is redundant.\n",
    "def _repr_png_(self):\n",
    "    \"\"\"Generate a PNG representation of the Colormap.\"\"\"\n",
    "    import io\n",
    "    from PIL import Image\n",
    "    import numpy as np\n",
    "    IMAGE_SIZE = (400, 50)\n",
    "    X = np.tile(np.linspace(0, 1, IMAGE_SIZE[0]), (IMAGE_SIZE[1], 1))\n",
    "    pixels = self(X, bytes=True)\n",
    "    png_bytes = io.BytesIO()\n",
    "    Image.fromarray(pixels).save(png_bytes, format='png')\n",
    "    return png_bytes.getvalue()\n",
    "    \n",
    "def _repr_html_(self):\n",
    "    \"\"\"Generate an HTML representation of the Colormap.\"\"\"\n",
    "    import base64\n",
    "    png_bytes = self._repr_png_()\n",
    "    png_base64 = base64.b64encode(png_bytes).decode('ascii')\n",
    "    return ('<img ' +\n",
    "            'alt=\"' + self.name + ' color map\" ' +\n",
    "            'title=\"' + self.name + '\"' +\n",
    "            'src=\"data:image/png;base64,' + png_base64 + '\">')\n",
    "    \n",
    "import matplotlib as mpl\n",
    "mpl.colors.Colormap._repr_png_ = _repr_png_\n",
    "mpl.colors.Colormap._repr_html_ = _repr_html_"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Calling with no arguments returns all colors from the current default\n",
    "color cycle:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.color_palette()"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Other variants on the seaborn categorical color palette can be referenced by name:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.color_palette(\"pastel\")"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Return a specified number of evenly spaced hues in the \"HUSL\" system:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.color_palette(\"husl\", 9)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Return all unique colors in a categorical Color Brewer palette:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.color_palette(\"Set2\")"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Return one of the perceptually-uniform colormaps included in seaborn:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.color_palette(\"flare\", as_cmap=True)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Return a customized cubehelix color palette:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.color_palette(\"ch:s=.25,rot=-.25\", as_cmap=True)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Return a light-themed sequential colormap to a seed color:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.color_palette(\"light:#5A9\", as_cmap=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "seaborn-py38-latest",
   "language": "python",
   "name": "seaborn-py38-latest"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
